package com.ecut.xzh.controller;

import com.ecut.xzh.dto.RoommatePageDTO;
import com.ecut.xzh.result.PageResult;
import com.ecut.xzh.result.Result;
import com.ecut.xzh.service.RoommateService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author XZH
 */
@RestController
@RequestMapping("/roommate")
@Slf4j
public class RoommateController {

    @Resource
    private RoommateService roommateService;

    /**
     *  分页查询室友信息
     * @param roommatePageDTO
     * @return
     */
    @GetMapping("/page")
    public Result<PageResult> pageRoommate(RoommatePageDTO roommatePageDTO){
        log.info("开始室友分页查询");
        PageResult pageResult = roommateService.pageRoommate(roommatePageDTO);
        return Result.success(pageResult);
    }

    /**
     *  导出Excel
     * @return
     */
    @GetMapping("/excel")
    public void exportExcel(HttpServletResponse response) throws IOException {
        log.info("开始导出学生信息至Excel文件");
        roommateService.exportExcel(response);
    }

}
